import pygame
import time

pygame.init()


SIZE = [551, 551]
FILL = [37, 37, 37]

screen = pygame.display.set_mode(SIZE)
# screen = pygame.display.set_mode([0, 0], pygame.FULLSCREEN)
width = screen.get_width()
height = screen.get_height()

clock = pygame.time.Clock()


def draw_scene():
    step = 0
    for i in range(12):
        pygame.draw.line(screen, "white", [step, 0], [step, 1050], 1)
        pygame.draw.line(screen, "white", [0, step], [1050, step], 1)
        step += 50


class Hero:
    def __init__(self, x, y, w, h):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.color = "red"
        self.step = 50

    def draw(self):
        pygame.draw.rect(screen, "red", [self.x, self.y, self.w, self.h])

    def move_left(self):
        if self.x > 1:
            print(self.x)
            self.x -= self.step

    def move_right(self):
        if self.x <= width - self.w * 2:
            print(self.x)
            self.x += self.step

    def move_up(self):
        if self.y > 1:
            self.y -= self.step

    def move_down(self):
        if self.y <= height - self.w * 2:
            self.y += self.step


hero = Hero(1, 1, 49, 49)
keys_pressed = []
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == 97:
                hero.move_left()
            if event.key == 100:
                hero.move_right()
            if event.key == 119:
                hero.move_up()
            if event.key == 115:
                hero.move_down()
        # if event.type == pygame.KEYDOWN:
        #     keys_pressed.append(event.key)

        # if event.type == pygame.KEYUP:
        #     try:
        #         keys_pressed.remove(event.key)
        #     except:
        #         pass
        if event.type == pygame.QUIT:
            done = True

    screen.fill(FILL)
    draw_scene()
    # for key in keys_pressed:
    #     if key == pygame.K_w:
    #         hero.move_up()
    #         time.sleep(0.1)
    #     if key == pygame.K_s:
    #         hero.move_down()
    #         time.sleep(0.1)
    #     if key == pygame.K_a:
    #         hero.move_left()
    #         time.sleep(0.1)
    #     if key == pygame.K_d:
    #         hero.move_right()
    #         time.sleep(0.1)
    hero.draw()

    pygame.display.flip()

    clock.tick()
    pygame.display.set_caption(f"FPS --> {int(clock.get_fps())}")


pygame.quit()
